//
//  XMPropertyInfoView.m
//  XMJJ_zml
//
//  Created by apple on 2025/5/10.
//

#import "XMPropertyInfoView.h"

@interface XMPropertyInfoView ()

@property (nonatomic, strong) UILabel *moneyLabel;
@property (nonatomic, strong) UILabel *usableLabel;

@end

@implementation XMPropertyInfoView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self creatUI];
    }
    return self;
}

- (void)creatUI {
    self.backgroundColor = kColorHEX(0xF5F5F5);
    [self setPartCornerWithRectCorner:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadius:KScaleWidth(16.0)];
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(KScaleWidth(10.0), KScaleWidth(16.0), self.width - KScaleWidth(10.0)*2, KScaleWidth(96.0))];
    contentView.backgroundColor = kColorHEX(0xffffff);
    [contentView setCornerRadius:KScaleWidth(12.0)];
    [self addSubview:contentView];
    
    {
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(10.0), KScaleWidth(7.0), KScaleWidth(60.0), KScaleWidth(30.0)) font:KFontSize(14.0) textColor:kColorHEX(0x333333)];
        titleLabel.text = @"我的收益";
        [contentView addSubview:titleLabel];
        [contentView addSubview:self.moneyLabel];
        
        UIButton *detailBtn = [UIButton buttonWithType:UIButtonTypeCustom font:KFontSize(12.0) frame:CGRectMake(contentView.width - KScaleWidth(72.0), KScaleWidth(7.0), KScaleWidth(72.0), KScaleWidth(30.0)) title:@"明细" titleColor:kColorHEX(0x999999) image:@"mine_detail_icon"];
        [detailBtn layoutButtonWithEdgeInsetsStyle:CSButtonEdgeInsetsStyleRight ImageTitleSpace:KScaleWidth(2.0)];
        [detailBtn addTarget:self action:@selector(detailCheckAction:) forControlEvents:UIControlEventTouchUpInside];
        [contentView addSubview:detailBtn];
    }
    
    UIView *usableBgView = [[UIView alloc] initWithFrame:CGRectMake(0, KScaleWidth(42.0), contentView.width, contentView.height - KScaleWidth(42.0))];
    usableBgView.backgroundColor = kColorHEX(0xFDF8E3);
    [contentView addSubview:usableBgView];
    {
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(12.0), 0, KScaleWidth(80.0), usableBgView.height) font:KFontSize(14.0) textColor:kColorHEX(0x333333)];
        titleLabel.text = @"可提现余额";
        [usableBgView addSubview:titleLabel];
        [usableBgView addSubview:self.usableLabel];
        
        [usableBgView addSubview:self.usableLabel];
        UIButton *putForwardBtn = [UIButton buttonWithType:UIButtonTypeCustom font:KFontSize(14.0) frame:CGRectMake(usableBgView.width - KScaleWidth(12.0) - KScaleWidth(86.0), (usableBgView.height - KScaleWidth(28.0))/2, KScaleWidth(86.0), KScaleWidth(28.0)) title:@"立即提现" titleColor:kColorHEX(0x333333)];
        putForwardBtn.backgroundColor = kColorHEX(0xFFD800);
        [putForwardBtn setCornerRadius:putForwardBtn.height/2];
        [putForwardBtn addTarget:self action:@selector(putForwardAction:) forControlEvents:UIControlEventTouchUpInside];
        [usableBgView addSubview:putForwardBtn];
    }
    //交易
    UIView *dealView = [[UIView alloc] initWithFrame:CGRectMake(0, KScaleWidth(128.0), self.width, KScaleWidth(135.0))];
    dealView.backgroundColor = kColorHEX(0xffffff);
    [self addSubview:dealView];
    
    {
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(16.0), KScaleWidth(4.0), dealView.width - KScaleWidth(16.0)*2, KScaleWidth(32.0)) font:KBoldFontSize(16.0) textColor:kColorHEX(0x333333)];
        titleLabel.text = @"我的交易";
        [dealView addSubview:titleLabel];
        
        UIScrollView *dealItemBgView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, titleLabel.maxY, dealView.width, KScaleWidth(40.0))];
        dealItemBgView.contentSize = CGSizeMake(KScaleWidth(13.0) + (KScaleWidth(97.0) + KScaleWidth(8.0))*4, dealItemBgView.height);
        dealItemBgView.showsHorizontalScrollIndicator = NO;
        [dealView addSubview:dealItemBgView];
        NSArray *titleArr = @[@"我的见面", @"见面箱", @"我的订单", @"浏览记录"];
        NSArray *imgIconArr = @[@"mine_deal_mymeet_icon", @"mine_deal_meetbox_icon", @"mine_deal_myorder_icon", @"mine_deal_browseRecord_icon"];
        for (int i = 0; i < titleArr.count; i ++) {
            UIButton *itemBtn = [UIButton buttonWithType:UIButtonTypeCustom font:KFontSize(14.0) frame:CGRectMake(KScaleWidth(13.0) + (KScaleWidth(97.0) + KScaleWidth(8.0))*i, KScaleWidth(3.0), KScaleWidth(97.0), KScaleWidth(33.0)) title:titleArr[i] titleColor:kColorHEX(0x666666) image:imgIconArr[i]];
            itemBtn.backgroundColor = kColorHEX(0xF1F1F1);
            [itemBtn setCornerRadius:KScaleWidth(4.0)];
            [itemBtn layoutButtonWithEdgeInsetsStyle:CSButtonEdgeInsetsStyleLeft ImageTitleSpace:KScaleWidth(3.0)];
            [itemBtn addTarget:self action:@selector(itemSelectAction:) forControlEvents:UIControlEventTouchUpInside];
            itemBtn.tag = 6000 + i;
            [dealItemBgView addSubview:itemBtn];
        }
    }
}

//查看明细
- (void)detailCheckAction:(UIButton *)button {
    if (self.delegate && [self.delegate respondsToSelector:@selector(checkDetail)]) {
        [self.delegate checkDetail];
    }
}

//提现
- (void)putForwardAction:(UIButton *)button {
    if (self.delegate && [self.delegate respondsToSelector:@selector(putForward)]) {
        [self.delegate putForward];
    }
}

//交易类型选择
- (void)itemSelectAction:(UIButton *)button {
    if (self.delegate && [self.delegate respondsToSelector:@selector(checkOrderListWithOrderType:)]) {
        [self.delegate checkOrderListWithOrderType:button.tag - 6000];
    }
}

#pragma mark - Init
- (UILabel *)moneyLabel {
    if (!_moneyLabel) {
        _moneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(76.0), KScaleWidth(7.0), self.width - KScaleWidth(76.0) - KScaleWidth(60.0), KScaleWidth(30.0)) font:KBoldFontSize(18.0) textColor:kColorHEX(0x000000)];
        _moneyLabel.text = @"--";
    }
    return _moneyLabel;
}

- (UILabel *)usableLabel {
    if (!_usableLabel) {
        _usableLabel = [[UILabel alloc] initWithFrame:CGRectMake(KScaleWidth(90.0), 0, self.moneyLabel.width, KScaleWidth(96.0) - KScaleWidth(42.0)) font:KFontSize(15.0) textColor:kColorHEX(0xDD4B39)];
        _usableLabel.text = @"--";
    }
    return _usableLabel;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
